﻿using System.Collections.Generic;
using System.Linq;

namespace _1_16
{
    class Supplider
    {
        readonly string name;
        public string Name { get { return name; } }

        readonly int suppliderID;
        public int SuppliderID { get { return suppliderID; } }

        public Supplider(string name, int suppliderID)
        {
            this.name = name;
            this.suppliderID = suppliderID;
        }

        public static List<Supplider> GetSampleSuppliders()
        {
            return new List<Supplider>
            {
                new Supplider(name: "s1", suppliderID: 1),
                new Supplider(name: "s2", suppliderID: 2),
            };
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}", name, suppliderID);
        }
    }

    class Product
    {
        readonly string name;
        public string Name { get { return name; } }

        readonly decimal price;
        public decimal Price { get { return price; } }

        readonly int suppliderID;
        public int SuppliderID { get { return suppliderID; } }
        public Product(string name, decimal price, int suppliderID)
        {
            this.name = name;
            this.price = price;
            this.suppliderID = suppliderID;
        }

        public static List<Product> GetSampleProducts()
        {
            return new List<Product>
            {
                new Product(name: "West Side Story", price: 9.99m, suppliderID: 1),
                new Product(name: "Assassins", price: 14.99m, suppliderID: 1),
                new Product(name: "Frogs", price: 13.99m, suppliderID: 2),
                new Product(name: "Sweeny", price: 10.99m, suppliderID: 2)
            };
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}", name, price);
        }
    }

    class Program
    {
        static void Main_()
        {
            List<Product> products = Product.GetSampleProducts();
            List<Supplider> suppliders = Supplider.GetSampleSuppliders();
            var filltered = from p in products
                            join s in suppliders
         on p.SuppliderID equals s.SuppliderID
                            where p.Price > 10
                            orderby s.Name, p.Name
                            select new { SupplierName = s.Name, ProductName = p.Name };
            foreach (var v in filltered)
            {
                System.Console.WriteLine("Supplier={0}; Product={1}", v.SupplierName,v.ProductName);
            }
        }
    }
}
//Lineq借用了SQL的语法和一些思路。